﻿@model XPressify.Models.SearchResulstsModel
@using XPressify.Models
@using XPressify.Data.Helpers

@{
    ViewBag.Title = "Found search results";
}

<h2>Found search results</h2>

<table>
        <tr>
            <th width="50px">
                
            </th>
            <th>
                Name
            </th>
            <th>
            </th>
        </tr>
        @foreach(var item in Model.FoundSubjects)
        {
            <tr>
                <td height="50px">
                    @if (item.SubjectType == SubjectType.User)
                    {
                        <a href='@Url.Action("ProfileView", "Profile", new { id = item.SubjectId })' class="nobtn">
                            <img src= "@item.SubjectPicturePath" alt="Profile picture" title="Profile picture" style="width: 50px;height: 50px;" />
                        </a>
                    }
                    else if (item.SubjectType == SubjectType.Event && item.SubjectPicturePath != "")
                    {
                        <a href='@Url.Action("EventDetails", "Event", new { id = item.SubjectId })' class="nobtn">
                            <img src= "@item.SubjectPicturePath" alt="Cover picture" title="Cover picture" style="width: 50px;height: 50px;" />
                        </a>
                    }
                    else if (item.SubjectType == SubjectType.Group && item.SubjectPicturePath != "")
                    {
                        <a href='@Url.Action("GroupDetails", "Group", new { id = item.SubjectId })' class="nobtn">
                            <img src= "@item.SubjectPicturePath" alt="Cover picture" title="Cover picture" style="width: 50px;height: 50px;" />
                        </a>
                    }
                    else if (item.SubjectType == SubjectType.Page && item.SubjectPicturePath != "")
                    {
                        <a href='@Url.Action("PageDetails", "Page", new { id = item.SubjectId })' class="nobtn">
                            <img src= "@item.SubjectPicturePath" alt="Cover picture" title="Cover picture" style="width: 50px;height: 50px;" />
                        </a>
                    }
                </td>
                <td>
                    @if (item.SubjectType == SubjectType.User)
                    {
                        @Html.ActionLink(item.SubjectFullname, "ProfileView", "Profile", new { id = item.SubjectId }, new { @class = "nobtn" })
                    }
                    else if (item.SubjectType == SubjectType.Event)
                    {
                        @Html.ActionLink(item.SubjectFullname, "EventDetails", "Event", new { id = item.SubjectId }, new { @class = "nobtn" })
                    }
                    else if (item.SubjectType == SubjectType.Group)
                    {
                        @Html.ActionLink(item.SubjectFullname, "GroupDetails", "Group", new { id = item.SubjectId }, new { @class = "nobtn" })
                    }
                    else if (item.SubjectType == SubjectType.Page)
                    {
                        @Html.ActionLink(item.SubjectFullname, "PageDetails", "Page", new { id = item.SubjectId }, new { @class = "nobtn" })
                    }
                </td>
            
                <td style="text-align:right">
                    @if (item.Relationship == null)
                    {
                        if (item.SubjectType == SubjectType.User)
                        {
                            @Html.ActionLink("Add as a friend", "AddFriend", "User", new { Id = item.SubjectId }, new { @class = "test" })
                        }
                        else if (item.SubjectType == SubjectType.Event)
                        {
                            @Html.ActionLink("Join", "BecomeMember", "Event", new { Id = item.SubjectId }, new { @class = "test" })
                        }
                        else if (item.SubjectType == SubjectType.Page)
                        {
                            @Html.ActionLink("Join", "BecomeMember", "Page", new { Id = item.SubjectId }, new { @class = "test" })
                        }
                    }
                    else if (item.ConfirmButton)
                    {
                        if (item.SubjectType == SubjectType.User)
                        {
                            @Html.ActionLink("Confirm friend", "ConfirmRelationship", "User", new { Id = item.Relationship.Id }, new { @class = "test" })
                        }
                        else if (item.SubjectType == SubjectType.Event)
                        {
                            @Html.ActionLink("Join", "ConfirmRelationship", "Event", new { id = item.Relationship.Id }, new { })
                        }
                        else if (item.SubjectType == SubjectType.Group)
                        {
                            @Html.ActionLink("Join", "ConfirmRelationship", "Group", new { id = item.Relationship.Id }, new { })
                        }
                        else if (item.SubjectType == SubjectType.Page)
                        {
                            @Html.ActionLink("Join", "ConfirmRelationship", "Page", new { id = item.Relationship.Id }, new { })
                        }
                    }
                </td>            
            </tr>
    
        }
    
</table>